<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>个人中心</title>
    <!-- import CSS -->
    <link rel="stylesheet" href="https://cdn.staticfile.org/element-ui/2.15.9/theme-chalk/index.css">
    <!-- 引入axios -->
    <script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.min.js"></script>
    <!-- 引入Vue -->
    <script src="https://cdn.staticfile.org/vue/2.6.14/vue.min.js"></script>
    <!-- import Element UI -->
    <script src="https://cdn.staticfile.org/element-ui/2.15.9/index.min.js"></script>
    <link rel="stylesheet" href="css/Myself.css">
    <script src="../echarts/echarts.min.js"></script>
</head>
<body>
<div id="app">
    <el-container>
        <el-header height="150px">
            <div style="width: 1400px;margin: 0 auto">
                <img src="../imgs/logo.png" width="300px">
                <a href="">首页</a>
                <el-divider direction="vertical"></el-divider>
                <a href="">热点资讯</a>
                <el-divider direction="vertical"></el-divider>
                <a href="">商家入驻</a>
                <el-divider direction="vertical"></el-divider>
                <a href="">社会招聘</a>
                <el-divider direction="vertical"></el-divider>
                <a href="">校园招聘</a>
                <el-divider direction="vertical"></el-divider>
                <a href="">帮助</a>
                <el-divider direction="vertical"></el-divider>
                <span style="float: right;font-size: 15px;margin-top: 35px">
                    欢迎回来<a href="JavaScript:void(0)" style="text-decoration: none">{{nickname}}</a>
                    &nbsp&nbsp&nbsp
                    <a href="JavaScript:void(0)" style="text-decoration: none" @click="logout">退出登录</a>
                </span>
            </div>
        </el-header>
        <el-container>
            <el-aside width="200px">
                <el-menu
                        default-active="1"
                        class="el-menu-vertical-demo"
                        :unique-opened="true"
                        @Select="handleSelect"
                        @open="handleOpen"
                        @close="handleClose">
                    <el-menu-item index="1">
                        <i class="el-icon-s-home"></i>
                        <span slot="title">我的</span>
                    </el-menu-item>
                    <el-menu-item index="2">
                        <i class="el-icon-s-order"></i>
                        <span slot="title">我的订单</span>
                    </el-menu-item>
                    <el-menu-item index="3">
                        <i class="el-icon-shopping-cart-full"></i>
                        <span slot="title">我的购物车</span>
                    </el-menu-item>
                    <el-menu-item index="4">
                        <i class="el-icon-setting"></i>
                        <span slot="title">修改密码</span>
                    </el-menu-item>
                    <el-submenu index="5">
                        <template slot="title">
                            <i class="el-icon-map-location"></i>
                            <span>地址管理</span>
                        </template>
                        <el-menu-item-group>
                            <el-menu-item index="5-1">新增地址</el-menu-item>
                            <el-menu-item index="5-2">地址列表</el-menu-item>
                        </el-menu-item-group>
                    </el-submenu>
                </el-menu>
            </el-aside>
            <el-main>
                <el-row>
                    <el-col span="11" style="margin-right: 10px">
                        <el-card>
                            <div id="orderNum" style="width: 450px; height: 450px;"></div>
                        </el-card>
                    </el-col>
                    <el-col span="11">
                        <el-card>
                            <div id="cartNum" style="width: 450px; height: 450px;"></div>
                        </el-card>
                    </el-col>
                </el-row>
            </el-main>
        </el-container>
    </el-container>
</div>
</body>
<script>
    let v = new Vue({
        el: '#app',
        data: function () {
            return {
                nickname: localStorage.getItem('nickname'),
                userId: localStorage.getItem("userId"),
            }
        },
        methods: {
            handleOpen(key, keyPath) {
                console.log("handleOpen = " + key, keyPath);
            },
            handleClose(key, keyPath) {
                console.log("handleClose = " + key, keyPath);
            },
            handleSelect(key, keyPath) {
                console.log(key)
                if (key === '2') {
                    location.href = 'Order.html'
                } else if (key === '3') {
                    location.href = 'ShoppingCart.html'
                } else if (key === '4') {
                    location.href = 'ChangePassword.html'
                } else if (key === '5-1') {
                    location.href = 'addAddress.html'
                } else if (key === '5-2') {
                    location.href = 'AddressList.html'
                }
            },
            logout() {
                location.href = '../login.html'
            },
        },
        created: function () {
            axios.get('/order/orderNum', {
                params: {
                    userId: localStorage.getItem("userId")
                }
            })
                .then(function (response) {
                    let responseBody = response.data;
                    if (responseBody.state === 20000) {
                        console.log(responseBody.data);
                        var myChart = echarts.init(
                            document.getElementById('orderNum'));
                        var option = {
                            title: {
                                text: '每日订单数量统计',
                                subtext: 'Daily order quantity statistics',
                                left: 'center'
                            },
                            tooltip: {
                                trigger: 'axis',
                                axisPointer: {
                                    type: 'shadow'
                                }
                            },
                            grid: {
                                left: '3%',
                                right: '4%',
                                bottom: '3%',
                                containLabel: true
                            },
                            dataset: [{
                                source: responseBody.data
                            }],
                            xAxis: [{
                                type: 'category',
                            }],
                            yAxis: [{
                                type: 'value',
                                name: '订单数量',
                                min: 0,
                                max: 25,
                                interval: 5,
                                axisLabel: {
                                    formatter: '{value} 单'
                                }
                            }],
                            series: [{
                                type: 'bar',
                                encode: {
                                    x: 'time',
                                    y: 'num'
                                }
                            }],
                        }
                        myChart.setOption(option);
                    }
                })
            axios.get('/cart/cartNum', {
                params: {
                    userId: localStorage.getItem("userId")
                }
            })
                .then(function (response) {
                    let responseBody = response.data;
                    if (responseBody.state === 20000) {
                        console.log(responseBody.data)
                        var myChart = echarts.init(
                            document.getElementById('cartNum'));
                        var option = {
                            title: {
                                text: '每日购物车数量统计',
                                subtext: 'Daily cart quantity statistics',
                                left: 'center'
                            },
                            tooltip: {
                                trigger: 'axis',
                                axisPointer: {
                                    type: 'shadow'
                                }
                            },
                            grid: {
                                left: '3%',
                                right: '4%',
                                bottom: '3%',
                                containLabel: true
                            },
                            dataset: [{
                                source: responseBody.data
                            }],
                            xAxis: [{
                                type: 'category',
                                axisTick: {
                                    alignWithLabel: true
                                }
                            }],
                            yAxis: [{
                                type: 'value',
                                name: '购物车商品数量',
                                min: 0,
                                max: 25,
                                interval: 5,
                                axisLabel: {
                                    formatter: '{value} 件'
                                }
                            }],
                            series: [{
                                type: 'bar',
                                encode: {
                                    x: 'time',
                                    y: 'num'
                                },
                                barWidth: '60%'
                            }],
                        }
                        myChart.setOption(option);
                    }
                })
        }
    })
</script>
</html>